package com.lz.kunkun.messageservice.util;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.context.annotation.PropertySource;

@PropertySource("classpath:application.properties")
public class WangJianHttpUtil {		
public static Integer sendMes(String phone,String mesText) throws HttpException, IOException {
HttpClient client = new HttpClient();
System.out.println(PropertyUtil.getProperty("wangjian.mes.url"));
PostMethod post = new PostMethod(PropertyUtil.getProperty("wangjian.mes.url")); 
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
NameValuePair[] data ={ new NameValuePair("Uid", PropertyUtil.getProperty("wangjian.mes.user")),new NameValuePair("Key", PropertyUtil.getProperty("wangjian.mes.key")),new NameValuePair("smsMob",phone),new NameValuePair("smsText",mesText)};
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:"+statusCode);
for(Header h : headers)
{
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("gbk")); 
System.out.println(result); //打印返回消息状态
post.releaseConnection();
return Integer.valueOf(result);
}
public static String getReason(Integer num) {
	Map<Integer,String> map=new HashMap<Integer,String>();
	map.put(-1, "没有该用户账户");
	map.put(-2, "接口密钥不正确 ,不是账户登陆密码");
	map.put(-21, "MD5接口密钥加密不正确");
	map.put(-3, "短信数量不足");
	map.put(-11, "该用户被禁用");
	map.put(-14, "短信内容出现非法字符");
	map.put(-4, "手机号格式不正确");
	map.put(-41, "手机号码为空");
	map.put(-42, "短信内容为空");	
	map.put(-51, "短信签名格式不正确");
	map.put(-2, "短信签名太长,建议签名10个字符以内");
	map.put(-6, "IP限制");
	return map.get(num);
}
}